package com.boss;

import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.stream.Collectors;

/**
 * @ClassName User
 * @Description
 * @Author xinggh
 * @Date 2020/8/14 14:05
 * @Version 1.0
 **/
public class User {

    private Integer age;

    public Integer getAge() {
        return age;
    }

    /**
     * 大于20岁
     */
    public static void remove(List<User> userList) {
        userList.stream().filter(user -> user.getAge() <= 20).collect(Collectors.toList());
    }


    public int[] getLeastNumbers(int[] arr, int k) {
        if (arr.length == 0) {
            return new int[0];
        }
        Queue<Integer> pq = new PriorityQueue<>((v1, v2) -> v2 - v1);
        for (int num : arr) {
            if (pq.size() <= 10) {
                pq.offer(num);
            } else if (num < pq.peek()) {
                pq.poll();
                pq.offer(num);
            }
        }

        int[] res = new int[pq.size()];
        int idx = 0;
        for (int num : pq) {
            res[idx++] = num;
        }
        return res;
    }


    public static void main(String[] args) {
        User user = new User();
    }
}
